package com.hxy.manager.activity.bill;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.hxy.manager.R;

public class BillNianhuo extends Activity {
	private ListView listView;
	// ListView列表适配器
	private BaseAdapter listViewAdapter;
	// 当前选择
	private int selecteItem = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.bill_nianhuo_activity);
		setTitle("年货单");
		getActionBar().setDisplayHomeAsUpEnabled(true);// 向上返回
		listView = (ListView) findViewById(R.id.listView1);
	}

	void loadNianhuo() {

		/*
		 * 
		 * //获取所有通讯录联系人 MakeTable ct = new MakeTable(this); users =
		 * ct.getAllData(); /* 并没有解决逆序 for (int start = 0, end = users.length -
		 * 1; start < end; start++, end--) { LeiXing temp = users[end];
		 * users[end] = users[start]; users[start] = temp; }
		 * 
		 * //listView列表实现适配器 listViewAdapter = new BaseAdapter() {
		 * 
		 * 
		 * 
		 * @Override public View getView(int position, View convertView,
		 * ViewGroup parent) {
		 * 
		 * //逆序的实现，貌似会带来listView的卡顿。position是listview的位置。position2是的数据库的位置 int
		 * position2= users.length-1-position;
		 * 
		 * //加入,这个类是自定义的静态类。 ViewHolder holder;
		 * 
		 * if(convertView==null){ /* TextView textView= new
		 * TextView(Store.this); textView.setTextSize(22); convertView=textView;
		 * 
		 * 
		 * final LayoutInflater inflater = (LayoutInflater)
		 * getApplicationContext().getSystemService(Context.
		 * LAYOUT_INFLATER_SERVICE); convertView =
		 * inflater.inflate(R.layout.item,null); holder = new ViewHolder();
		 * holder.icon=(ImageView)convertView.findViewById(R.id.imageView);
		 * holder.name=(TextView)convertView.findViewById(R.id.nameView);
		 * holder.price=(TextView)convertView.findViewById(R.id.priceView);
		 * convertView.setTag(holder);
		 * 
		 * } else { holder=(ViewHolder)convertView.getTag(); }
		 * 
		 * 
		 * 
		 * /************************三元运算符**************************** // String
		 * price =
		 * users[position].getPrice()==null?"":users[position].getPrice(); //
		 * ((TextView)convertView).setText(""+users[position].getName()
		 * +"\n      "+position+"价格:  "+price); //
		 * ((TextView)convertView).setText((position+1)+".书名："+users[position].
		 * getName()+"\n    "+"价格:  "+price);
		 * 
		 * 
		 * holder.icon.setImageResource(R.drawable.store);
		 * holder.name.setText(users[position2].getName());
		 * holder.price.setText(users[position2].getPrice());
		 * 
		 * // position是listview的位置。 if(position==selecteItem){
		 * convertView.setBackgroundColor(0x5f1296db); // Toast.makeText(this,
		 * "text", Toast.LENGTH_LONG).show(); } else{
		 * convertView.setBackgroundColor(0); } return convertView; }
		 * 
		 * @Override public long getItemId(int position) { // TODO
		 * Auto-generated method stub return position; }
		 * 
		 * @Override public Object getItem(int position) { // TODO
		 * Auto-generated method stub return users[position]; }
		 * 
		 * @Override public int getCount() { // TODO Auto-generated method stub
		 * return users.length; } }; //设置listView控件的适配器
		 * listView.setAdapter(listViewAdapter); //长按
		 * listView.setOnItemLongClickListener(new
		 * AdapterView.OnItemLongClickListener() {
		 * 
		 * @Override public boolean onItemLongClick(AdapterView<?> arg0, View
		 * arg1, int arg2, long arg3) { // TODO Auto-generated method stub
		 * selecteItem=arg2; //逆序的实现，貌似会带来listView的卡顿。 int selecteItem2=
		 * users.length-1-selecteItem; //
		 * Toast.makeText(Store.this,"长按修改",Toast.LENGTH_SHORT).show();
		 * if(users[selecteItem2].getNumber()!=null){ Intent intent3 = new
		 * Intent(Store.this,Update.class); intent3.putExtra("scanCode",
		 * users[selecteItem2].getNumber()); startActivity(intent3); } else {
		 * Toast.makeText(Store.this, "没有数据",Toast.LENGTH_SHORT).show(); }
		 * 
		 * return true;
		 * 
		 * } } ); //短按 listView.setOnItemClickListener(new
		 * AdapterView.OnItemClickListener() {
		 * 
		 * @Override public void onItemClick(AdapterView<?> arg0, View arg1, int
		 * arg2, long arg3) { // TODO Auto-generated method stub /* //记录单击列的位置
		 * selecteItem=arg2; //刷新列表 listViewAdapter.notifyDataSetChanged();
		 * 
		 * 
		 * selecteItem=arg2; //逆序的实现，貌似会带来listView的卡顿。 int selecteItem2=
		 * users.length-1-selecteItem;
		 * 
		 * if(users[selecteItem2].getNumber()!=null){ Intent intent3 = new
		 * Intent(Store.this,Show.class); intent3.putExtra("scanCode",
		 * users[selecteItem2].getNumber()); startActivity(intent3); } else {
		 * Toast.makeText(Store.this, "空",Toast.LENGTH_SHORT).show(); }
		 * 
		 * 
		 * }
		 * 
		 * });
		 * 
		 * 
		 */

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.bill_nianhuo_comsumer, menu);
		return super.onCreateOptionsMenu(menu);
	}

	public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) {
		case android.R.id.home: // 默认添加的，左边的TItle向上返回
			finish();
			break;
		case R.id.consumer_add:// 保存
			startActivity(new Intent(BillNianhuo.this, BillNianhuoConsumerAddActivity.class));
			// Toast.makeText(Store.this,"点击了添加！",Toast.LENGTH_SHORT).show();
			break;
		case R.id.action_find:
			// Toast.makeText(this, "点击了查询！", Toast.LENGTH_LONG).show();
		//	new Today.FindDialog(this).show();
			break;
		case R.id.action_statistics:

			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setTitle("统计");
			// 04 builder.setIcon(R.drawable.scan);
			// 下一步进行主页面adapter的列表自定义。

			//builder.setMessage("菜品：" + TP.length + " 种");
			builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

				@Override
				public void onClick(DialogInterface arg0, int arg1) {
					// TODO Auto-generated method stub
				}
			});
			builder.create();
			builder.show();
			break;
		/*
		 * case R.id.action_logs: startActivity(new
		 * Intent(Today.this,Logs.class)); //
		 * Toast.makeText(Store.this,"点击了添加！",Toast.LENGTH_SHORT).show(); break;
		 * 
		 */

		}
		return false;

	}

}
